package service

import (
	"context"
	"github.com/gin-gonic/gin"
	"github.com/google/wire"
	"kratosRecoverPanic/pkg/gin_encoder"
)

// ProviderSet is service providers.
var ProviderSet = wire.NewSet(NewGreeterService, NewRecoverService, NewGinService)

type HttpService interface {
	GetPrefix() string
	NewServiceRoutes(r *gin.RouterGroup)
}

func ginHttpHandle(ff func(*gin.Context, context.Context, *gin_encoder.Response)) func(*gin.Context) {
	f := func(c *gin.Context) {
		ctx, _, result, err := gin_encoder.GetCtxAndResult(c)
		if err != nil {
			return
		}
		ff(c, ctx, result)
	}
	return f
}
